$(document).ready(function(){
	var idName;
	var that;
	var load = $('span#load').attr('url');
	
	$('select.ajax-change').on('change',function(){
		that = $(this);
		var val = that.val();
		idName = that.attr('id');
		
		if(val !== null)
		{
			var schedule = {
				url : that.attr('url'),
				option : val,
				datatype : that.attr('data-type')
			}
			
			that.siblings('span.loading').html('<img src="'+load+'">');
			ajax_change(schedule);
		}
	});
	
	$('input[type=text].ajax-change').on('blur',function(){
		that = $(this);
		var val = that.val();
		var orgval = that.attr('orgval');
		idName = that.attr('id');
		if(val.length >= 3 && val !== orgval)
		{
			var schedule = {
				url : that.attr('url'),
				option : val,
				datatype : that.attr('data-type')
			}
			that.siblings('span.loading').html('<img src="'+load+'">');
			ajax_change(schedule);
		}
	});

function ajax_change(data){
	
	$.ajax({
	  type: "POST",
	  url: data.url,
	  data:{option:data.option,
			type:data.datatype
	  }
	}).done(function(output){
		if(output == true){
			that.siblings('span.loading').html('<i class="icon-ok"></i>');
		}else{
			that.siblings('span.loading').html('<i class="icon-remove"></i>');
		}
	});
}

});